home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / GNUUCP_2 / SOURCE / UUXQT.C < prev    next >
Text File  |  1990-06-17  |  4KB  |  145 lines

  1. /*  uuxqt.c: Lol Grant. 23rd. Sept 1987.
  2.          read uucp C.<hostname>XXXXX files and execute the
  3.          commands in them.
  4. */
  5.  
  6. #include "includes.h"
  7. #include "uucp.h"
  8.  
  9. #define RMAIL
  10.  
  11. int
  12. uuxqt(debug)
  13. int debug;
  14.      {
  15.  
  16.         int i;
  17.         char command[60], addressee[60], input[60], output[60], line[132];
  18.         char file[NAMESIZE];
  19.         char *xfile;
  20.         char tmp_str[255];
  21.         FILE *fd;
  22.         int pid, status;
  23.         cuserid(who);        /* Finger out who we are */
  24.         strcpy(host_name, "uuxqt");    /* We know who this is */
  25.  
  26.         read_params(NULL);
  27.  
  28.         if (chdir(Spool) != 0)
  29.             {
  30.                 printf("can't change to %s\n", Spool);
  31.                 logit("FAILED", "can't change to Spool");
  32.                 return(EXIT_ERR);
  33.                 }
  34.         logit("OK", "startup");
  35.  
  36.         if (!work_scan(NULL, "X"))
  37.             {
  38.                 logit("Completed", "No Work");
  39.                 return(EXIT_OK);
  40.                 }
  41.         while ((xfile = work_next()) != NULL)
  42.             {
  43.                 sprintf(file, "%s:%s", Spool, (char *)munge_filename(xfile));
  44.                 if ((fd = fopen(file, "rb")) == NULL)
  45.                     {
  46.                         logit("CAN'T READ", file);
  47.                         remove(file);
  48.                         continue;
  49.                         }
  50.                 logit("FILE", file); 
  51.                 input[0] = output[0] = (char)NULL;
  52.  
  53.                 while (fgets(line, sizeof(line), fd) != NULL) {
  54.                 line[strlen(line) - 1] = '\0';
  55.                 DEBUG(2, "uuxqt:  %s\n", line);
  56.                 switch (line[0]) {
  57.                    case 'U':
  58.                     break;
  59.                 case 'I':
  60.                     sprintf(input, "%s:%s", Spool, &line[2]);
  61.                     DEBUG(2, "uuxqt: input %s\n", input);
  62.                     break;
  63.                 case 'O':
  64.                     sprintf(output, "%s:%s", Spool, &line[2]);
  65.                     DEBUG(2, "uuxqt: output %s\n", output);
  66.                     break;
  67.                 case 'C':
  68.                     sscanf((char *)&line[2], "%s %s", command, addressee);
  69.                     DEBUG(2, "uuxqt: command %s\n", command);
  70.                     DEBUG(2, "uuxqt: addressee %s\n", addressee);
  71.                     break;
  72.                 case 'R':
  73.                     break;
  74.                 default:
  75.                     break;
  76.                 }
  77.         }
  78.         fclose(fd);
  79.         if ((i = strlen(input)) == 0)
  80.             strcpy(input, NULL_DEVICE);
  81.         if ((i = strlen(output)) == 0)
  82.             strcpy(output, NULL_DEVICE);
  83.         sprintf(line, "%s %s < %s > %s", command, addressee, input, output);
  84.         logit("XQT", line);
  85.         if (invoke(command, addressee, input, output) != EXIT_OK)
  86.             {
  87.                 sprintf(line, "%s %s %s %s", command, addressee, input, output);
  88.                 logit("FAILED", line);
  89.                 if (invoke(command, postmaster, input, output) != EXIT_OK) 
  90.                     {
  91.                         sprintf(line, "%s %s %s %s", command, postmaster, 
  92.                                 input, output);
  93.                         logit("FAILED", line);
  94.                         logit("Check Spool Directory for Inconsistencies", xfile);
  95.                         exit(EXIT_ERR);
  96.                         /* continue; */
  97.                         }
  98.                 }
  99.         if (remove(file) == 0)
  100.             {
  101.                 DEBUG(2, "deleted %s\n", file);
  102.                 }
  103.           else
  104.             {
  105.                 DEBUG(0, "Can't delete %s\n", file);
  106.                 }
  107.         if (strcmp(input, NULL_DEVICE))
  108.         if (remove(input) == 0)
  109.             {
  110.                 DEBUG(2, "deleted %s\n", input);
  111.                 }
  112.             else
  113.             {
  114.                 DEBUG(0, "Can't delete %s\n", input);
  115.                 }
  116.         if (strcmp(output, NULL_DEVICE))
  117.             if (remove(output) == 0)
  118.                 {
  119.                     DEBUG(2, "deleted %s\n", output);
  120.                     }
  121.             else
  122.                 {
  123.                     DEBUG(0, "Can't delete %s\n", output);
  124.                     }
  125.         }
  126.         work_done();
  127.         logit("OK", "finished");
  128.         return(EXIT_OK);
  129.     }
  130.  
  131. /* Invoke the local program. Return its status (0 == ok) or -1 */
  132. int invoke(command, addressee, input, output)
  133. char *command, *addressee, *input, *output;
  134. {
  135.     int i, pid;
  136.     struct STATUS status;
  137.     char tmp[255];
  138.     if (strcmp(command, "rmail") == 0)
  139.         {
  140.             return(do_rmail(addressee, input, output));
  141.             }
  142.     logit("Unknown Command", command);
  143.     return(-1);
  144.     }
  145.